﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sicurezza.CA.DataProvider;
using System.Security.Cryptography;

namespace Sicurezza.CA.Manager
{
    public class AuthenticationManager
    {
        private static AuthenticationDataProvider dataProvider = new AuthenticationDataProvider();


        public static bool ValidateUser(string username, string password)
        {
            byte[] data = ASCIIEncoding.Unicode.GetBytes(password);
            byte[] result;

            SHA1 sha = new SHA1CryptoServiceProvider();
            // This is one implementation of the abstract class SHA1.
            result = sha.ComputeHash(data);

            string shaPassword = Convert.ToBase64String(result);

            return dataProvider.Authenticate(username, shaPassword);
        }
    }
}
